package com.hoyo.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.hoyo.domain.CountInfo;
import com.hoyo.domain.Movie;

@Mapper
public interface MovieMapper {
	
	@Insert("insert into movie values(0,#{catalogId},#{realPath},#{movieName}, '',#{sortNumber},#{createTime},#{isChecked})")
	void save(Movie movie)throws Exception;
	
	@Select("select mv.id, mv.movie_name, mv.real_path, mci.comment_amount "
			+ "from movie mv left join movie_count_info mci "
			+ "on mci.movie_id=mv.id "
			+ "where catalog_id=#{0} order by sort_number")
	List<Movie> findMoviesByCatalogId(int catalogId)throws Exception;
	
	@Select("select real_path from movie where id=#{0}")
	String findUrlById(int movieId)throws Exception;
	
	@Update("update movie_count_info set play_amount=play_amount+#{1} where movie_id=#{0}")
	void updatePlayAmountByMovieIdAndPlusAmount(int movieId, int amount)throws Exception;
	
	@Select("select sum(play_amount) playAmount, sum(comment_amount) commentAmount, sum(danmu_amount) bulletAmount, "
			+ "(select count(*) from user) userAmount from movie_count_info")
	CountInfo getCountInfo()throws Exception;
	
	@Update("delete from movie where catalog_id=#{0}")
	void removeByCatalogId(int catalogId);
}
